<?php

class tplRrecent extends StudyBuddy\Template\Template {

    protected static function func(&$a) {

        if (!empty($a['date_reg'])) {
            $a['hts_ago'] = \StudyBuddy\TimeAgo::format(new \DateTime($a['date_reg']));
        }
        if (!empty($a['resource_size'])) {
            if($a['resource_size']>1024*1024) {
                $temp = (int)$a['resource_size']/(1024*1024);
                $a['size'] = round($temp) . ' Mb';
            } elseif($a['resource_size']>1024) {
                $temp = (int)$a['resource_size']/1024;
                $a['size'] = round($temp) . ' Kb';
            } else {
                $a['size'] = $a['resource_size'] . ' bytes';
            }
        }
        $aLevel = array(
            1 => 'P1',
            2 => 'P2',
            3 => 'P3',
            4 => 'P4',
            5 => 'P5',
            6 => 'P6',
            7 => 'S1',
            8 => 'S2',
            9 => 'S3'
        );
        $aSubject = array(
            1 => 'E Maths',
            2 => 'A Maths',
            3 => 'Physics'
        );
        if (!empty($a['level'])) {
            $a['level_d'] = $aLevel[$a['level']];
        }
        if (!empty($a['subject'])) {
            $a['subject_d'] = $aSubject[$a['subject']];
        }
        if($a['is_admin']) {
            $a['rremove'] = ' | <a href="#" title="Remove" onclick="if(confirm(\'Do you wan\&#39;t to remove this resource?\')){window.location=\'http://'.$_SERVER['HTTP_HOST'].'/index.php?a=deleteresource&rid='.$a['_id'].'\';}">Remove</a>';
        }
    }

    protected static $vars = array(
        '_id' => '0', //1
        'title' => '', //2
        'description' => '', //3
        'username' => '', //4
        'ulink' => '', //5
        'avtr' => '/images/avatar.png', //6
        'is_admin' => '0', //7
        'hts_ago' => '', //8
        'level_d' => '', //9
        'subject_d' => '', //10
        'resource_file' => '', //11
        'size' => '', //12
        'rremove' => '' //13
        
        
    );
    protected static $tpl = '
        <div class="box">
            <table>
                <tr>
                    <td width="45">%9$s</td>
                    <td width="60">%10$s</td>
                    <td width="330"><a target="_blank" href="/w/resources/%11$s" title="%2$s" style="text-decoration:none;">%2$s</a></td>
                    <td width="120" align="center">
                        <a target="_blank" href="/w/resources/%11$s" title="Download">Download</a>
                        %13$s
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <div class="box-right">
                            <div class="boxr-bot">
                                <div class="boxr-bot-img">
                                    <a href="JavaScript:void(0)"><img alt="" src="%6$s" width="26" height="26" /></a>
                                </div>
                                <div class="boxr-bot-txt">
                                    resource by %5$s %8$s
                                </div>
                            </div>
                        </div>
                    </td>
                    <td align="center">%12$s</td>
                </tr>
            </table>
        </div>';

}
